package com.vanrin.aweatherforecast.view;

import android.content.Context;
import android.graphics.Color;
import android.graphics.PixelFormat;
import android.util.AttributeSet;
import android.view.SurfaceHolder;
import android.view.SurfaceView;

public class MySurfaceView extends SurfaceView implements SurfaceHolder.Callback {

    SurfaceHolder mHolder;
    private DrawThread mThread;

    private dwList dwl;

    public MySurfaceView(Context context , AttributeSet attrs) throws InterruptedException {

        super(context , attrs);

        getHolder().addCallback(this);

        dwl = new dwList();

        dwl.begin_record();

        dwl.record(30, 30, 0, 0);

        dwl.record(100, 100, 1, Color.GREEN);

        Thread.sleep(50);

        dwl.record(100, 30, 1, Color.YELLOW);

        Thread.sleep(60);

        dwl.record(30, 30, 1, Color.BLUE);

        Thread.sleep(40);

        dwl.record(30, 100, 1, Color.RED);

    }

    public void surfaceCreated(SurfaceHolder holder) {

        mHolder = holder;

        mThread = new DrawThread();

        mThread.start();

    }

    public void surfaceDestroyed(SurfaceHolder holder) {

        mThread = null;

    }

    public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {

    }

    // ----------------------------------------------------------------------

    class DrawThread extends Thread {

        DrawThread() {

            super();

        }

        @Override
        public void run() {

            dwl.draw(mHolder);

        }

    }

}
